package com.faceye.core.repository.jdbc;


import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * 连接池
 */
public class DataSourceFactory {
    private static Map<String, DataSource> DATA_SOURCES=null;
    private static DataSourceFactory INSTANCE=null;
    static{
        DATA_SOURCES = new HashMap<String,DataSource>();
    }

    public static synchronized  DataSourceFactory getInstance(){
        if(INSTANCE==null) {
            INSTANCE = new DataSourceFactory();
        }
        return INSTANCE;
    }

    public DataSource getDataSource(String dbName){
        return DATA_SOURCES.get(dbName);
    }

    /**
     *
     * 私有构造器
     */
    private DataSourceFactory(){
        initDataSource();
    }

    /**
     * 初始化datasource
     */
    private void initDataSource(){
//        for(String dbName: DataSourceConstatns.DB_NAMES){
//            Map<String,String> props = DataSourceConstatns.getProps(dbName);
//            DataSource dataSource = DataSourceBuilder.builder(props);
//            DATA_SOURCES.put(dbName,dataSource);
//        }
    }

}
